package com.soxing.braindata.domain.vo;

import com.google.common.collect.Sets;
import com.soxing.braindata.dao.entity.Role;
import com.soxing.braindata.dao.entity.UserInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Set;

/**
 * 用户Vo
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserVo {
    /**
     * 用户账号
     */
    private String userNum;
    /**
     * 用户密码
     */
    private String userPwd;
    /**
     * 用户类型
     */
    private Integer userType;

    /**
     * 用户信息
     */
    private UserInfo userInfo;
    /**
     * 用户角色信息
     */
    private List<Role> roleList;

    /**
     * 获取用户所属分中心
     *
     * @return
     */
    public Set<String> getSitePkId() {
        Set<String> sitePkIdSet = Sets.newHashSet();
        if (CollectionUtils.isEmpty(roleList)) {
            return sitePkIdSet;
        }
        roleList.forEach(role -> {
            sitePkIdSet.add(role.getSitePkId());
        });
        return sitePkIdSet;
    }

    /**
     * 获取用户所属课题编码
     *
     * @return
     */
    public Set<String> getSubjectCode() {
        Set<String> codeSet = Sets.newHashSet();
        if (CollectionUtils.isEmpty(roleList)) {
            return codeSet;
        }
        roleList.forEach(role -> {
            codeSet.add(role.getSubjectPkId());
        });
        return codeSet;
    }
}
